package com.usian.goods.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.usian.goods.bean.Goods;
import com.usian.goods.service.GoodsService;
import com.usian.goodstype.bean.Goodstype;
import com.usian.goodstype.service.GoodstypeService;
import com.usian.supplier.bean.Supplier;
import com.usian.supplier.service.SupplierService;

@Controller
@RequestMapping("/goods")
public class GoodsAction {
	@Autowired
	private GoodsService goodsService;
	@Autowired
	private SupplierService supplierService;
	@Autowired
	private GoodstypeService goodstypeService;
	/**
	 * 	商品查询
	 * */
	@RequestMapping("/findgoods")
	@ResponseBody
	public List<Goods> findgoods(Goods goods){
		System.out.println(goods);
		List<Goods> findgoods = goodsService.findgoods(goods);
		return findgoods;
	}
	/**
	 * 	供应商下拉查询
	 * */
	@RequestMapping("/findsupplier")
	@ResponseBody
	public List<Supplier> findsupplier(Supplier supplier){
		System.out.println(supplier);
		List<Supplier> findsupplier = supplierService.findsupplier(supplier);
		System.out.println(findsupplier);
		return findsupplier;
	}
	/**
	 * 	商品类型下拉查询
	 * */
	@RequestMapping("/findgoodstype")
	@ResponseBody
	public List<Goodstype> findsupplier(Goodstype goodstype){
		List<Goodstype> findgoodstype= goodstypeService.findgoodstype(goodstype);
		System.out.println(findgoodstype);
		return findgoodstype;
	}
	/**
	 * 	商品删除
	 * */
	@RequestMapping("/delgoods")
	public String delgoods(Integer id){
		goodsService.delgoods(id);
		return "redirect:/jsp/goods/goods.jsp";
	}
	/**
	 * 	商品ID查询
	 * */
	@RequestMapping("/findgoodsId")
	public String findgoodsId(Integer id ,HttpServletRequest request){
		Goods goods = goodsService.findgoodsId(id);
		request.getSession().setAttribute("findgoods", goods);
		return "redirect:/jsp/goods/updategoods.jsp";
	}
	/**
	 * 添加商品
	 * */
	@RequestMapping("/addgoods")
	public String addgoods(Goods goods){
		goods.setMaxNum(100);
		goods.setMinNum(15);
		System.out.println(goods);
		goodsService.addgoods(goods);
		return "redirect:/jsp/goods/goods.jsp";
	}
	/**
	 * 修改商品
	 * */
	@RequestMapping("/updategoods")
	public String updategoods(Goods goods){
		goods.setMaxNum(100);
		goods.setMinNum(15);
		goodsService.updategoods(goods);
		return "redirect:/jsp/goods/goods.jsp";
	}
	
	
}
